#include "Node.h"

Node::Node()
{
	_left = NULL;
	_right = NULL;
	_c = 0;
	_num = 0;
}

Node::Node(char c, unsigned num)
{
	_left = NULL;
	_right = NULL;
	_c = c;
	_num = num;
}

Node::Node(Node* left, Node* right)
{
	_left = left;
	_right = right;
	_num = left->_num + right->_num;
	_c = 0;
}

void Node::clear()
{
	deleteTree(this);
}

unsigned Node::getNum()
{
	return _num;
}

char Node::getChar()
{
	return _c;
}

void Node::deleteTree(Node* root)
{
	if(root->_left != NULL)
		deleteTree(root->_left);
	if(root->_right != NULL)
		deleteTree(root->_right);
	delete root;
}

INode* Node::left()
{
	return _left;
}

INode* Node::right()
{
	return _right;
}

void Node::pickEOF()
{
	Node* current = this;
	while(NULL != current->_left)
		current = current->_left;
	Node* left = new Node(0,1);
	Node* right = new Node(current->getChar(),current->getNum());
	current->_left = left;
	current->right = right;
}